import React from "react";
import { useDispatch } from "react-redux";
import { addTodo } from "@/store/slice/todoSlice";
function TodoHeader() {
  const dispatch = useDispatch();
  const add = (e) => {
    if (e.keyCode === 13) {
      dispatch(addTodo({ name: e.target.value }));
      e.target.value = "";
    }
  };
  return (
    <header className="header">
      <h1>todos</h1>
      <input
        className="new-todo"
        placeholder="请输入内容..."
        autoFocus
        onKeyUp={add}
      />
    </header>
  );
}

export default TodoHeader;
